package com.hckjsec.website.controller;

import java.util.List;

import com.hckjsec.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.hckjsec.common.annotation.Log;
import com.hckjsec.common.core.controller.BaseController;
import com.hckjsec.common.core.domain.AjaxResult;
import com.hckjsec.common.enums.BusinessType;
import com.hckjsec.website.domain.WebSiteSpecial;
import com.hckjsec.website.service.IWebSiteSpecialService;
import com.hckjsec.common.utils.poi.ExcelUtil;
import com.hckjsec.common.core.page.TableDataInfo;

/**
 * 专项专题Controller
 * 
 * @author cyt
 * @date 2021-10-19
 */
@RestController
@RequestMapping("/system/special")
public class WebSiteSpecialController extends BaseController
{
    @Autowired
    private IWebSiteSpecialService webSiteSpecialService;

    /**
     * 查询专项专题列表
     */
    @GetMapping("/list")
    public TableDataInfo list(WebSiteSpecial webSiteSpecial)
    {
        startPage();
        if(!SecurityUtils.isAdmin(SecurityUtils.getUserId())){
            webSiteSpecial.setDeptId(SecurityUtils.getDeptId());
        }
        List<WebSiteSpecial> list = webSiteSpecialService.selectWebSiteSpecialList(webSiteSpecial);
        return getDataTable(list);
    }

    /**
     * 导出专项专题列表
     */
    @Log(title = "专项专题", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(WebSiteSpecial webSiteSpecial)
    {
        if(!SecurityUtils.isAdmin(SecurityUtils.getUserId())){
            webSiteSpecial.setDeptId(SecurityUtils.getDeptId());
        }
        List<WebSiteSpecial> list = webSiteSpecialService.selectWebSiteSpecialList(webSiteSpecial);
        ExcelUtil<WebSiteSpecial> util = new ExcelUtil<WebSiteSpecial>(WebSiteSpecial.class);
        return util.exportExcel(list, "special");
    }

    /**
     * 获取专项专题详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(webSiteSpecialService.selectWebSiteSpecialById(id));
    }

    /**
     * 新增专项专题
     */
    @Log(title = "专项专题", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WebSiteSpecial webSiteSpecial)
    {
        webSiteSpecial.setDeptId(SecurityUtils.getDeptId());
        webSiteSpecial.setOperator(SecurityUtils.getUserId());
        return toAjax(webSiteSpecialService.insertWebSiteSpecial(webSiteSpecial));
    }

    /**
     * 修改专项专题
     */
    @Log(title = "专项专题", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WebSiteSpecial webSiteSpecial)
    {
        return toAjax(webSiteSpecialService.updateWebSiteSpecial(webSiteSpecial));
    }

    /**
     * 删除专项专题
     */
    @Log(title = "专项专题", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(webSiteSpecialService.deleteWebSiteSpecialByIds(ids));
    }
}
